package com.lzb.play.activity;

import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.CacheMemoryUtils;
import com.blankj.utilcode.util.CleanUtils;
import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.MetaDataUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.lzb.play.BaseAc;
import com.lzb.play.Content;
import com.lzb.play.R;
import com.lzb.play.databinding.ActivityMyBinding;

import java.io.File;
import java.util.List;

public class MyActivity extends BaseAc<ActivityMyBinding> implements View.OnClickListener {


    @Override
    protected int onCreate() {
        return R.layout.activity_my;
    }

    @Override
    protected void initView() {
        mDataBinding.ivMyBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.llMyRecord.setOnClickListener(this);
        mDataBinding.llClearCache.setOnClickListener(this);
        mDataBinding.llFeedback.setOnClickListener(this);
        mDataBinding.llPrivacy.setOnClickListener(this);
        mDataBinding.llAgreement.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.llMyRecord) {//我的录制
            startActivity(RecordActivity.class);
        } else if (id == R.id.llClearCache) {//清理缓存
            CleanUtils.cleanInternalCache();
            ToastUtils.showShort(getString(R.string.clear_suc));
            mDataBinding.tvCacheSize.setText(ConvertUtils.byte2FitMemorySize(FileUtils.getLength(PathUtils.getInternalAppCachePath()), 2));
        } else if (id == R.id.llFeedback) {//意见反馈
            startActivity(FeedbackActivity.class);
        } else if (id == R.id.llAgreement) {//用户协议

        } else if (id == R.id.llPrivacy) {//隐私政策

        }
    }

    @Override
    protected void initData() {
        mDataBinding.tvCacheSize.setText(ConvertUtils.byte2FitMemorySize(FileUtils.getLength(PathUtils.getInternalAppCachePath()), 2));
        mDataBinding.tvVersion.setText("v" + AppUtils.getAppVersionName());
    }

    @Override
    protected void onResume() {
        super.onResume();
        String path = PathUtils.getFilesPathExternalFirst() + Content.myRecord;
        List<File> files = FileUtils.listFilesInDir(path);
        mDataBinding.tvSize.setText(files.size() + "");
    }
}